package com.xxx.coll;

import java.util.Iterator;
import java.util.LinkedList;

/**
 * @version v1.0
 * @Description:
 * @Author zhanzhongxin
 * @Date 2021/7/20 15:35
 * @Copyright 博为峰
 */
public class LinkedListDemo {
    public static void main(String[] args) {
        //------------------------添加------------------------------------
        LinkedList linkedList = new LinkedList();
//        linkedList.addFirst("a");
//        linkedList.addFirst("b");
//        linkedList.addLast("c");

        //jdk1.6
        linkedList.offerFirst("a");
        linkedList.offerFirst("b");
        linkedList.offerLast("c");

        Iterator iterator = linkedList.iterator();
        while (iterator.hasNext()) {
            String s = (String) iterator.next();
            System.out.println(s);
        }

//        System.out.println(linkedList);

        //-------------------------获取-------------------------------------
//        System.out.println(linkedList.getFirst());//如果链表为空，抛出NoSuchElementException
//        System.out.println(linkedList.getLast());
        //jdk1.6
//        System.out.println(linkedList.peekFirst());//如果链表为空，返回null
//        System.out.println(linkedList.peekLast());

        //--------------------------删除--------------------------------------
//        linkedList.removeFirst();//如果链表为空，抛出NoSuchElementException
//        linkedList.removeLast();
        //jdk1.6
//        linkedList.pollFirst();//如果链表为空，返回null
//        linkedList.pollLast();
//        System.out.println(linkedList);
        /*
           addFirst
           addLast
           //jdk1.6
           offerFirst  有返回值 boolean
           offerLast   有返回值 boolean
         */

    }
}
